{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "def algorithm(nums1, nums2):\n",
    "    count1 = [0]*1001\n",
    "    count2 = [0]*1001\n",
    "    result = []\n",
    "    for i in range(len(nums1)):\n",
    "        count1[nums1[i]] +=1\n",
    "    for j in range(len(nums2)):\n",
    "        count2[nums2[j]] +=1\n",
    "    for k in range(1001):\n",
    "        if count1[k]*count2[k] > 0:\n",
    "            n = min(count1[k], count2[k])\n",
    "            for i in range(n):\n",
    "                result.append(k)\n",
    "    return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "nums1 = [1,2,2,1]\n",
    "nums2 = [2,2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 2]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "algorithm(nums1, nums2)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
